#include<iostream.h>
#include<conio.h>
template <class t>
class insertion
{
t a[25];
public:
void get(int);
void sort(int);
void display(int);
};
template <class t>
void insertion<t>::get(int n)
{
int i;
cout<<"Enter the array elements:";
for(i=0; i<n;i++)
cin>>a[i];
}
template <class t>
void insertion <t>::display(int n)
{
int i;
cout<<"\n The sorted array is";
for(i=0;i<n;i++)
cout<<a[i];
}
template <class t>
void insertion <t>::sort(int n)
{
int i,j;
t temp;
for(i=1;i<n;i++)
{
j=i;
while(j>=1)
{
if(a[j]<a[j-1])
{
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
j--;
}
}
}
void main()
{
int n;
insertion<int> i1;
insertion<float> i2;
clrscr();
cout<<"\n Insertion Sort on Integer Values";
cout<<"\n Enter the size of array:\n";
cin>>n;
i1.get(n);
i1.sort(n);
i1.display(n);
cout<<"\n Insertion Sort on Float Values";
cout<<"\n Enter the size of array:\n";
cin>>n;
i2.get(n);
i2.sort(n);
i2.display(n);
getch();
}